package com.hikvision.rfiddemo;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * author: zhangdi45
 * Date: 16:40 2023/11/27
 */
public class ThreadPoolManager {
    private static ScheduledExecutorService schedulerThreadExecutor;//
    private static ScheduledExecutorService singleThreadExecutor;
    private static ScheduledExecutorService singlePowerThreadExecutor;
    public static ScheduledExecutorService getScheduledExecutorService() {
        if (schedulerThreadExecutor == null) {
            synchronized (ThreadPoolManager.class){
                if (schedulerThreadExecutor == null) {
                    schedulerThreadExecutor = Executors.newScheduledThreadPool(6);
                }
            }
        }
        return schedulerThreadExecutor;
    }



    public static ScheduledExecutorService getSingleThreadExecutor() {
        if (singleThreadExecutor == null) {
            synchronized (ThreadPoolManager.class){
                if (singleThreadExecutor == null) {
                    singleThreadExecutor = Executors.newSingleThreadScheduledExecutor();
                }
            }
        }
        return singleThreadExecutor;
    }


    public static ScheduledExecutorService getSinglePowerThreadExecutor() {
        if (singlePowerThreadExecutor == null) {
            synchronized (ThreadPoolManager.class){
                if (singlePowerThreadExecutor == null) {
                    singlePowerThreadExecutor = Executors.newSingleThreadScheduledExecutor();
                }
            }
        }
        return singlePowerThreadExecutor;
    }

    public static void shutdown(){
        if (schedulerThreadExecutor != null){
            schedulerThreadExecutor.shutdown();
            schedulerThreadExecutor = null;
        }
        if (singleThreadExecutor != null){
            singleThreadExecutor.shutdown();
            singleThreadExecutor = null;
        }

        if (singlePowerThreadExecutor != null){
            singlePowerThreadExecutor.shutdown();
            singlePowerThreadExecutor = null;
        }


    }


}
